#include "logger.h"
#include <cstdio>

#if WIN32
#include <Windows.h>
#include <cstdarg>
#else
#include <varargs.h>
#endif

namespace vkinfer
{
    std::shared_ptr<VkLogger> logger = nullptr;

    void VkLogger::log(VkLogLevel level, const char* message, ...)
    {
        const char* level_string[6] = {
            "[FATAL]", "[ERROR]", "[WARNING]",
            "[INFO]", "[DEBUG]", "[TRACE]",
        };
        const uint32_t BUFFER_SIZE = 3200;
        char output_message[BUFFER_SIZE] = { 0 };
        va_list arg_ptr;
        va_start(arg_ptr, message);
        vsnprintf(output_message, BUFFER_SIZE, message, arg_ptr);
        va_end(arg_ptr);

        char output_message2[BUFFER_SIZE] = { 0 };
        sprintf(output_message2, "%s%s", level_string[int(level)], output_message);
        printf(output_message2);
#if WIN32
        OutputDebugStringA(output_message);
#endif
    }

    std::shared_ptr<VkLogger> VkLogger::get_logger()
    {
        if (logger == nullptr)
            logger = std::make_shared<VkLogger>();
        return logger;
    }
}
